/*

* ------------------------------------------------------------------------
* ------------------------------------------------------------------------
* |     Smart-Shop开源商城系统/ Java商城-首选电商平台系统 请务必保留此注释头信息
* |     开源地址: https://gitee.com/ningbo-qishan/gruul-mall
* ------------------------------------------------------------------------
* ------------------------------------------------------------------------
* |     可正常分享和学习源码,未经授权 不可商用！
* |     商业版中台购买/开源版商业授权 联系技术客服
* |     官网:  https://www.73app.cn/
* ------------------------------------------------------------------------
* ------------------------------------------------------------------------
* |     Copyright (c) 2016-2999 宁波启山智软科技有限公司
* |     版权所有 ,侵权必究！
* ------------------------------------------------------------------------

*/
package com.medusa.gruul.account.web.controller.api;


import com.medusa.gruul.account.api.model.MemberBalanceUpdateDto;
import com.medusa.gruul.account.model.vo.MemberBalanceRecordResVo;
import com.medusa.gruul.account.service.IMemberBalanceRecordService;
import com.medusa.gruul.common.core.annotation.EscapeLogin;
import com.medusa.gruul.common.core.util.Result;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @Description
 * @Author zhaokw
 * @Date 00:39 2020\7\4 0013
 **/
@RestController
@RequestMapping("/api")
public class ApiMemberBalanceRecordController {

    @Autowired
    private IMemberBalanceRecordService memberBalanceRecordService;

    @GetMapping("/getMemberBalanceRecord")
    @ApiOperation(value = "小程序端获取会员余额明细信息")
    @EscapeLogin
    public Result<MemberBalanceRecordResVo> getMemberBalanceRecord(
            @ApiParam(value = "指定页数", required = true) @RequestParam Integer page,
            @ApiParam(value = "数据条数", required = true) @RequestParam Integer size,
            @ApiParam(name = "yearMonth", value = "年月") @RequestParam(required = false) String yearMonth,
            @ApiParam(name = "memberInfoId", value = "会员id") @RequestParam(required = false) String userShopId,
            @ApiParam(name = "dealType", value = "交易类型 0-用户消费(购买商品) 1-微信充值 2-消费返利 3-退款成功 4-商品分销 5-提现") @RequestParam(required = false) Integer dealType
    ) {
        MemberBalanceRecordResVo memberBalanceRecords = memberBalanceRecordService.getMemberBalanceRecord(yearMonth, userShopId, page, size, dealType);
        return Result.ok(memberBalanceRecords);
    }

    @DeleteMapping("/memberBalanceRecord/{id}")
    @ApiOperation(value = "用户删除余额明细")
    @EscapeLogin
    public Result removeMemberBalanceRecord(
            @ApiParam(value = "用户余额明细id", required = true) @PathVariable(name = "id") Long id
    ) {
        memberBalanceRecordService.removeMemberBalanceRecord(id);
        return Result.ok();
    }


    @PostMapping("/memberBalanceModify")
    @ApiOperation(value = "测试扣退款会员余额变更")
    @EscapeLogin
    public Result<Boolean> memberBalanceModify(@RequestBody @Validated MemberBalanceUpdateDto memberBalanceUpdateDto) {
        Boolean flag = memberBalanceRecordService.memberBalanceModify(memberBalanceUpdateDto);
        return Result.ok(flag);
    }


}
